package com.bytedance.article.common.launchcrash;

import android.app.ActivityManager;
import android.app.ActivityManager;
import android.content.Context;
import android.os.Process;
import android.text.TextUtils;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.util.Iterator;

public final class g {
    private static String a;

    static {
        g.a = null;
    }

    public static boolean a(Context arg3) {
        boolean v0 = false;
        String v1 = g.b(arg3);
        if ((v1 == null || !v1.contains(":")) && (v1 != null && (v1.equals(arg3.getPackageName())))) {
            v0 = true;
        }

        return v0;
    }

    private static String a() {
        Throwable v0_1;
        BufferedReader v1_1 = null;
        String v0 = null;
        try {
            v1_1 = new BufferedReader(new InputStreamReader(new FileInputStream("/proc/" + Process.myPid() + "/cmdline"), "iso-8859-1"));
            StringBuilder v2_1 = new StringBuilder();
            while (true) {
                int v3 = v1_1.read();
                if (v3 <= 0) {
                    break;
                }

                v2_1.append(((char) v3));
            }
            v0 = v2_1.toString();
        } catch (Throwable v2) {
        } finally {
            if (v1_1 != null) {
                try {
                    v1_1.close();
                } catch (Exception v1_2) {
                }
            }

            return v0;
        }
    }

    public static String b(Context arg4) {
        Object v0_2;
        String v0 = g.a;
        try {
            if (!TextUtils.isEmpty(((CharSequence) v0))) {
                return v0;
            }

            int v1 = Process.myPid();
            Iterator v2 = ((ActivityManager) arg4.getSystemService(Context.ACTIVITY_SERVICE)).getRunningAppProcesses().iterator();
            do {
                if (!v2.hasNext()) {
                    v0 = g.a();
                    g.a = v0;
                    return v0;
                }

                v0_2 = v2.next();
            }
            while (((ActivityManager.RunningAppProcessInfo) v0_2).pid != v1);

            v0 = ((ActivityManager.RunningAppProcessInfo) v0_2).processName;
            g.a = v0;
            return v0;
        } catch (Throwable v0_1) {
            return g.a;
        }
    }
}

